package com.zrrd.learn.chapter04;

/**
 * 斐波那契数列
 *
 * @author asus
 * @version 1.0
 * @date 2023/5/27 14:36
 */
public class Fibonacci {
    //循环
    public static void main(String[] args) {
        int start = 1;
        int second = 1;
        System.out.print(start+"\t");
        System.out.print(second+"\t");
        int index=0;
        while(index++ <5){
            int t = start +second;
            System.out.print(start+second +"\t");
            start = second;
            second = t;
        }

    }

    //递归
    public static int fibonacci(int a){
        int num=0;
        if(a==1||a==2){
            num=1;
            return num;
        }else {
            return fibonacci(a - 1) + fibonacci(a - 2);
        }
    }
}
